﻿using System;
using System.Linq;

namespace CRMS.Models
{
    public class selfClassroomInfo
    {
        private Classroom cr = null;
        private TeachingBuilding tb = null;
        private ToUseClassroom tuc = null;
        public selfClassroomInfo(Classroom cr,TeachingBuilding tb,ToUseClassroom tuc)
        {
            this.cr = cr;
            this.tb = tb;
            this.tuc = tuc;
        }
        public string TeachingBuildingName
        {
            get
            {
                return tb.TeachingBuildingName;
            }
        }
        public int ClassroomId
        {
            get
            {
                return cr.ClassroomId;
            }
        }
        public string Floor 
        {
            get
            {
                return cr.Floor;
            }
           
        }
        public string Peorid
        {
            get
            {
                return tuc.Period;
            }
        }
    }
   public class SelfStudyRep
    {
       private StoreDBDataContext storeDB = new StoreDBDataContext();

       public IQueryable<selfClassroomInfo> getAllSelfCRInfo()
       {
           return from ct in
                      (from cr in storeDB.Classrooms
                       join tb in storeDB.TeachingBuildings
                       on cr.TeachingBuildingId equals tb.TeachingBuildingId
                       select new { cr, tb }
                  )
                  join tuc in storeDB.ToUseClassrooms
                  on ct.cr.ClassroomId equals tuc.ClassroomId
                  where tuc.UseStatus == '0'
                  select new selfClassroomInfo(ct.cr, ct.tb, tuc); 
                  
       }
       public IQueryable<selfClassroomInfo> getSelfCRInfo(string tbname,string period)
       {
           return from ct in
                      (from cr in storeDB.Classrooms
                       join tb in storeDB.TeachingBuildings
                       on cr.TeachingBuildingId equals tb.TeachingBuildingId
                       select new { cr, tb }
                  )
                  join tuc in storeDB.ToUseClassrooms
                  on ct.cr.ClassroomId equals tuc.ClassroomId
                  where tuc.UseStatus == '0'&& ct.tb.TeachingBuildingName == tbname && tuc.Period == period
                  select new selfClassroomInfo(ct.cr, ct.tb, tuc); 
                  
           
       }

    }
}
